//1.字符串 - 最长公共前缀
//解法一: 统一比较
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) 
    {
        string ret;
        for(int j = 0; j < strs[0].size(); j++) //列
        {
            char ch = strs[0][j];
            for(int i = 1; i < strs.size(); i++) //行
                if(strs[i][j] != ch || j == strs[i].size())
                    return ret;
            ret += ch;
        }
        return ret;
    }
};

//解法二: 两两比较
class Solution {
public:
    string find_common(string& s1, string& s2)
    {
        int i = 0;
        for(i = 0; i < s1.size() && i < s2.size(); i++)
            if(s1[i] != s2[i]) break;
        return s1.substr(0, i);
    }

    string longestCommonPrefix(vector<string>& strs) 
    {
        //两两比较
        string ret = strs[0];
        for(int i = 1; i < strs.size(); i++)
            ret = find_common(ret, strs[i]);
        return ret;
    }
};